package com.jtbd.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jtbd.domain.Course;
import com.jtbd.dto.request.CourseItemHttpDto;
import com.jtbd.dto.result.ResponseBaseData;
import com.jtbd.service.CourseManagementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
@Tag(name = "课程管理")
public class CourseManagementController {
    @Resource
    private CourseManagementService courseManagementService;

    @PostMapping("/addCourse")
    @Operation(summary = "添加课程")
    public ResponseBaseData<Long> addCourse(@Validated @RequestBody CourseItemHttpDto course) {
        return ResponseBaseData.success(courseManagementService.addCourse(course));
    }

    @GetMapping("/getCourseList")
    @Operation(summary = "获取课程列表")
    public ResponseBaseData<IPage<Course>> getCourseList(@Parameter(description = "校区ID") @Validated Long campusId, @Parameter(description = "页码") Integer pageIndex, @Parameter(description = "该页 请求数据的大小") Integer pageSize) {
        return ResponseBaseData.success(courseManagementService.getCourseList(campusId, pageIndex, pageSize));
    }

    @GetMapping("/getCourseListByCondition")
    @Operation(summary = "按条件获取课程列表")
    public ResponseBaseData<IPage<Course>> getCourseListByCondition(@Parameter(description = "校区ID") @Validated @NotNull Long campusId,
                                                                   @Parameter(description = "课程状态") Integer courseStatus,
                                                                   @Parameter(description = "课程等级") Integer courseLevel,
                                                                   @Parameter(description = "课程分类") Integer courseCategory,
                                                                   @Parameter(description = "课程类型") Integer courseType,
                                                                   @Parameter(description = "课程名称") String courseName,
                                                                   @Parameter(description = "页码") Integer pageIndex,
                                                                   @Parameter(description = "该页 请求数据的大小") Integer pageSize) {
        return ResponseBaseData.success(courseManagementService.getCourseListByCondition(campusId, courseStatus, courseLevel, courseCategory, courseType, courseName, pageIndex, pageSize));
    }
}
